// pages/my/my.js
var app = getApp();
var util = require('../../utils/util.js');
Page({
  data: {
    userInfo: {},
    list: [],
    total: 0,
    pageNum: 0,
    showNoneRefresh: false,
    imageUrl: app.imageUrl
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.initStores()
    wx.setNavigationBarTitle({
      title: app.shopInfo.shopName
    })
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    util.setColor(this);
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  onPullDownRefresh: function () {
    this.initStores()
  },
  initStores: function () {
    var that = this
    var params = { shopId: app.shopId }
    var encodingStr = app.ecbEncrypto(params)
    wx.request({
      url: app.url + '/cx/retail/stroeCache.do',
      data: encodingStr,
      method: 'POST',
      success: function (res) {
        var decodingStr = app.ecbDecrypto(res.data)
        var rest = JSON.parse(decodingStr)
        console.log(rest)
        if (rest.isSuccess == 0) {
          that.setData({ list: rest.storeInfo})
        } else {
        
        }
      },
      complete: function () {
        wx.stopPullDownRefresh()
      }
    })
  },
  callStore: function (event) {
    var index = event.currentTarget.dataset.index
    var phone = this.data.list[index].tel
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },
  openMap: function (event) {
    var index = event.currentTarget.dataset.index
    var store = this.data.list[index]
    var latitude = store.latitude
    var longitude = store.longitude
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
      scale: 28
    })
  }
})